import React from 'react'
import { EDealerType } from '../../AdjustTheRecord/List'
import { columnRenders } from '@/lib'
import apis from '@/apis/AboutQuota'
import dayjs from 'dayjs'
export enum EListType {
  CUSTOMER_TYPE = 'CUSTOMER_TYPE',
  AREA_CUSTOMER_TYPE = 'AREA_CUSTOMER_TYPE',
  AREA_TYPE = 'AREA_TYPE',
  MATERIAL_CLASS_TYPE = 'MATERIAL_CLASS_TYPE',
}

export const switchTypes = [
  { title: '客户维度', value: EListType.CUSTOMER_TYPE },
  { title: '片区+客户维度', value: EListType.AREA_CUSTOMER_TYPE },
  { title: '片区维度', value: EListType.AREA_TYPE },
  { title: '配额物料分类维度', value: EListType.MATERIAL_CLASS_TYPE },
]

export const queryUrls = {
  [EListType.CUSTOMER_TYPE]: apis.getQuotaTransmit,
  [EListType.AREA_CUSTOMER_TYPE]: apis.GetQuotaReleaseListByAreaClient,
  [EListType.AREA_TYPE]: apis.GetQuotaReleaseListByArea,
  [EListType.MATERIAL_CLASS_TYPE]: apis.GetQuotaReleaseListByMatClass,
}

export class TableColumns {
 
  constructor(private handelDelete ) {
    this.handelDelete = handelDelete
  }

  /* 客户维度 */
  CUSTOMER_TYPE = [
    // ['盘点周期', 'description', (text, record) => {
    //   let red = record.red == 'Y'
    //   return <span className={red ? 'red' : ''}>{text}</span>
    // }, { minWidth: '90px' }],
    ['客户编码', 'dealerCode',  (text, record) => {
      let red = record.red == 'Y'
      return <span className={red ? 'red' : ''}>{text}</span>
    }, { minWidth: '90px' }],
    ['客户名称', 'dealerName', null, { minWidth: '140px' }],
    ['销售组织', 'brandName', null, { minWidth: '60px' }],
    ['客户类型', 'dealerType', columnRenders.enum(EDealerType), { minWidth: '80px' }],
    ['所属管理区域', 'belongAreaName', null, { minWidth: '120px' }],
    {
      title: '配额开始时间', dataIndex: 'quotaStartTime', key: 'quotaStartTime', minWidth: '110px', render: (text) => {
        return text ? dayjs(text).format('YYYY-MM-DD') : ''
      }
    },
    {
      title: '配额结束时间', dataIndex: 'quotaEndTime', key: 'quotaEndTime', minWidth: '110px', render: (text) => {
        return text ? dayjs(text).format('YYYY-MM-DD') : ''
      }
    },
    {
      title: '数据来源', key: 'sourceFrom', minWidth: '60px', dataIndex: 'sourceFrom', render: (text) => (
        <span>{text == 'SYSTEM' ? '系统取数' : '手工导入'}</span>
      )
    },
    {
      title: '操作',
      dataIndex: 'operate',
      fixedWidth: '40px',
      render: columnRenders.operate([
        {
          title: '删除', action: (text: any, record: any) => { this.handelDelete(record) }
        },
      ])
    }
  ]

  /* 片区+客户维度 */
  AREA_CUSTOMER_TYPE = [
    ['配额有效期','quotaStartTime', (text, record) => {
      function getYear(item){
        return item && item.substring(0,10)
      }
      let isShow = Boolean(record.quotaStartTime)
      return <span>
        <span className={isShow?'':'isShow'}>{getYear(record.quotaStartTime||'')+'~'+getYear(record.quotaEndTime||'')}</span>
        <span className={isShow?'isShow':''}>{''}</span>
        </span>
    }, { minWidth: '120px' }],
    ['客户编码', 'dealerCode', null, { minWidth: '80px' }],
    ['客户名称', 'dealerName', null, { minWidth: '140px' }],
    ['客户类型', 'dealerType', columnRenders.enum(EDealerType), { minWidth: '80px' }],
    ['所属管理区域', 'belongAreaName', null, { minWidth: '90px' }],
    { title: '物料分类名称', dataIndex: 'groupName', minWidth: '200px', width: '20%' },
    {
      title: '当前动销/件',
      key: 'nowMove',
      dataIndex: 'nowMove',
      minWidth: '70px',
    },
    { title: '理论配额值/件', dataIndex: 'quotaCountNum', minWidth: '80px',render:(text)=><span>{text||0}</span> },
    { title: '片区申请配额/件', dataIndex: 'quotaNum', minWidth: '90px',
        render:(text)=> text || 0
    },
    // { title: '实际下达配额/件', dataIndex: 'quotaNum', minWidth: '90px'}
  ]

  /* 片区维度 */
  AREA_TYPE = [
    ['销售组织', 'brandName', null, { minWidth: '60px' }],
    ['片区', 'belongAreaName', null, { minWidth: '120px' }],
    ['配额有效期', 'quotaStartTime', (text, record) => {
      function getYear(item){
        return item && item.substring(0,10)
      }
      let isShow = Boolean(record.quotaStartTime)
      return <span>
        <span className={isShow?'':'isShow'}>{getYear(record.quotaStartTime||'')+'~'+getYear(record.quotaEndTime||'')}</span>
        <span className={isShow?'isShow':''}>{''}</span>
        </span>
    }, { minWidth: '120px' }],
    {
      title: '当前动销/件',
      key: 'nowMove',
      dataIndex: 'nowMove',
      minWidth: '70px',
    },
    { title: '理论配额值/件', dataIndex: 'quotaCountNum', minWidth: '80px',render:(text)=><span>{text||0}</span> },
    { title: '片区申请总配额/件', dataIndex: 'quotaNum', minWidth: '100px',
        render:(text)=> text || 0
    },
  ]

  /* 片区维度、配额物料分类维度--内嵌表格 */
  AREA_TYPE_SUB = [
    { title: '片区', dataIndex: 'belongAreaName', minWidth: '90px' },
    { title: '物料分类名称', dataIndex: 'groupName', minWidth: '200px', width: '20%' },
    {
      title: '当前动销/件',
      key: 'nowMove',
      dataIndex: 'nowMove',
      minWidth: '70px',
    },
    { title: '理论配额值/件', dataIndex: 'quotaCountNum', minWidth: '80px',render:(text)=><span>{text||0}</span> },
    { title: '片区申请配额/件', dataIndex: 'quotaNum', minWidth: '90px',
        render:(text)=> text || 0
    },
  ]

  /* 配额物料分类维度 */
  MATERIAL_CLASS_TYPE = [
    ['销售组织', 'brandName', null, { minWidth: '60px' }],
    { title: '物料分类名称', dataIndex: 'groupName', minWidth: '200px', width: '20%' },
    { title: '配额有效期', dataIndex: 'quotaStartTime', render: (text,record) => {
      function getYear(item){
        return item && item.substring(0,10)
      }
      let isShow = Boolean(record.quotaStartTime)
      return <span>
        <span className={isShow?'':'isShow'}>{getYear(record.quotaStartTime||'')+'~'+getYear(record.quotaEndTime||'')}</span>
        <span className={isShow?'isShow':''}>{''}</span>
        </span>
    }, minWidth: '120px' },
    {
      title: '当前动销/件',
      key: 'nowMove',
      dataIndex: 'nowMove',
      minWidth: '70px',
    },
    { title: '理论配额值/件', dataIndex: 'quotaCountNum', minWidth: '80px',render:(text)=><span>{text||0}</span> },
    { title: '片区申请总配额/件', dataIndex: 'quotaNum', minWidth: '100px',
        render:(text)=> text || 0
    },
  ]
  
  /* 配额物料分类维度--内嵌表格 */
  MATERIAL_CLASS_TYPE_SUB = this.AREA_TYPE_SUB

}